package net.oschina.app.fragment.favorite.msg;

import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import net.oschina.app.R;
import net.oschina.app.adapter.my.ActiveFavoriteAdapter;
import net.oschina.app.bean.TweetLike;
import net.oschina.app.bean.TweetLikeList;
import net.oschina.app.constant.Constants;
import net.oschina.app.fragment.BaseFragment;
import net.oschina.app.util.UIUtils;
import net.oschina.app.util.URLGet;

import java.util.List;

/**
 * Created by YL on 2017/4/5.
 */
public class MsgFavoriteFragmnt extends BaseFragment {
    private XRecyclerView mView;
    private List<TweetLike> mTweetLikes;
    @Override
    protected View initView() {
        mView = (XRecyclerView) View.inflate(UIUtils.getContext(), R.layout.f_software_fragment, null);
        mView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return mView;
    }

    @Override
    protected void setData() {
        String path = Constants.My_Active_Favour_Path; //http://localhost:8080/oschina/list/my_tweet_like_list/page.xml
        URLGet urlGet = new URLGet();
        urlGet.getData(path, TweetLikeList.class, new URLGet.OnURLGetLitener<TweetLikeList>() {
            @Override
            public void showSuccess(TweetLikeList bean) {
                mTweetLikes = bean.getList();
                dealCommonSuccess(mTweetLikes);
            }
            @Override
            public void showError(Exception e) {

            }
        });
    }

    @Override
    protected void showSuccess() {
        ActiveFavoriteAdapter adapter = new ActiveFavoriteAdapter(mTweetLikes);
        mView.setAdapter(adapter);
        if(mTweetLikes !=null && mTweetLikes.size()>0){
            View footView = View.inflate(UIUtils.getContext(),R.layout.my_recycler_foot_view,null);
            mView.setFootView(footView);
        }
        changeView(mView);
    }
}
